export const androidLogin = async () => {
    var mainActivity = plus.android.runtimeMainActivity();
    console.log(mainActivity);
    var GoogleSignInOptions = plus.android.importClass(
        `com.google.android.gms.auth.api.signin.GoogleSignInOptions`);
    const clientId = 'android clientId'
    var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(clientId)
        .requestServerAuthCode(clientId)
        .requestEmail()
        .requestProfile()
        .build();
    //创建GoogleClient
    var GoogleSignIn = plus.android.importClass(`com.google.android.gms.auth.api.signin.GoogleSignIn`);
    var mGoogleClient = GoogleSignIn.getClient(mainActivity, gso)
    var signInIntent = plus.android.invoke(mGoogleClient, 'getSignInIntent')
    //跳转登录
    var CODE_REQUEST = 200;
    mainActivity.startActivityForResult(signInIntent, CODE_REQUEST);
    //获取登录回调
    mainActivity.onActivityResult = async function (requestCode, resultCode, data) {
        if (requestCode == CODE_REQUEST) {
            var GoogleSignIn = plus.android.importClass(
                `com.google.android.gms.auth.api.signin.GoogleSignIn`);
            console.log(GoogleSignIn, "GoogleSignIn")
            var account = new GoogleSignIn().getLastSignedInAccount(mainActivity)
            if (account) {
                let idToken = plus.android.invoke(account, 'getIdToken')
                console.log(idToken, "idToken")
                return idToken
            }
        }
    }
}

export const iosLogin = () => {
    uni.login({
        provider: 'google',
        success: async (res) => {
            if (res.authResult && res.authResult.access_token) {
                console.log('进入接口调用流程，access_token:', res.authResult.access_token);
                return res.authResult.access_token
            }
        },
        fail: function (err) {
            console.log(err, err)
        }
    });
}



